/*
 * @Author: zhouwei wei.zhou@flip.fun
 * @Date: 2024-04-07 22:52:05
 * @LastEditors: zhouwei wei.zhou@flip.fun
 * @LastEditTime: 2024-04-07 22:55:07
 * @FilePath: /50/手撕系列/promise.race.js
 * @Description: 这是默认设置,请设置`customMade`,app-program-77 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

/**
 *
 * @param { Promise<any>[] } args
 */
function race(args) {
	return new Promise(function (resolve, reject) {
		for (let index = 0; index < args.length; index++) {
			const promiseItem = args[index]
			Promise.resolve(promiseItem)
				.then(res => {
					resolve(res)
				})
				.catch(err => {
                    reject(err)
                })
		}
	})
}
